# -*- coding:utf-8 -*-
products=[["iphone",6888],["MacPro",14800],["小米6",2499],["Coffee",31],["Book",60],["Nike",699]]

#从products列表提取出商品名与价格
name=[]
price=[]
for i in range(len(products)):
    name.append(products[i][0])
    price.append(products[i][1])

#打印商品列表
print("-"*6,"商品列表","-"*6,sep=" ")#打印标题
for i in range(len(products)):
    print(name[i],price[i],sep="\t")#打印商品名与价格

#询问用户想买什么
shop_car=[]
shop_cost=[]
print("想买啥?（输入q退出）")
while True:
    want=input(">>>")
    if want=='q':#用户输入q时退出循环
        break
    if want in name:#若输入商品存在，放入购物车
        shop_car.append(want)
        shop_cost.append(price[name.index(want)])
        print(want,"已加入购物车",sep='')
    else:#若输入商品不存在，提示错误
        print("该商品不存在！")

#打印购物车
print("_"*6,"购买的商品列表","_"*6,sep=" ")#标题
for i in range(len(shop_car)):
    print(shop_car[i],shop_cost[i],sep="\t")#打印购物车商品名与价格

# 当使用非ASCII码时要在前面，具体可以看报错提示的pep-0263，完成作业要认真
